home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 76 / DVD Actual 1 Marzo 2003.iso / Trial / TurboCAD 7.1 Pro / Data.Cab / F29023_ctlTcViewer.ctl < prev    next >
Encoding:
Text File  |  2000-11-10  |  5.0 KB  |  233 lines

  1. VERSION 5.00
  2. Begin VB.UserControl ctlTcViewer 
  3.    BorderStyle     =   1  'Fixed Single
  4.    ClientHeight    =   4320
  5.    ClientLeft      =   0
  6.    ClientTop       =   0
  7.    ClientWidth     =   4716
  8.    ControlContainer=   -1  'True
  9.    KeyPreview      =   -1  'True
  10.    ScaleHeight     =   360
  11.    ScaleMode       =   3  'Pixel
  12.    ScaleWidth      =   393
  13. End
  14. Attribute VB_Name = "ctlTcViewer"
  15. Attribute VB_GlobalNameSpace = False
  16. Attribute VB_Creatable = True
  17. Attribute VB_PredeclaredId = False
  18. Attribute VB_Exposed = True
  19. Option Explicit
  20. Public Event ClickGraphic(gxGr As Graphic, dist As Double)
  21.  
  22. Dim gxDwg As Drawing
  23. Dim gxVw  As View
  24. Dim bAttached As Boolean
  25. Dim dblAperture As Double
  26. Dim bUpdate As Boolean
  27.  
  28. Public Sub Refresh()
  29.     Cls
  30.     If (bAttached) Then
  31.         If (bUpdate) Then
  32.             gxVw.Refresh
  33.         End If
  34.     End If
  35. End Sub
  36.  
  37. Public Sub Scroll(dy As Long, dx As Long)
  38.  
  39.     If (bAttached) Then
  40.     
  41.         On Error GoTo VwZoom
  42.          gxVw.Camera.Slide gxVw.ViewHeight() * dy / 10, gxVw.ViewWidth() * dx / 10
  43.         Exit Sub
  44. VwZoom:
  45.         Dim yTop As Double
  46.         Dim xLeft As Double
  47.         
  48.         On Error GoTo Err
  49.         
  50.         xLeft = gxVw.ViewLeft + gxVw.ViewWidth() * dx / 10
  51.         yTop = gxVw.ViewTop - gxVw.ViewHeight() * dy / 10
  52.         
  53.         gxVw.Update = False
  54.         
  55.         gxVw.ViewLeft = xLeft
  56.         gxVw.ViewTop = yTop
  57.     
  58.     End If
  59. Err:
  60. End Sub
  61.  
  62. Public Sub Zoom(factor As Double)
  63.  
  64.     If (bAttached) Then
  65.         If (factor <> 0) Then
  66.             On Error GoTo VwZoom
  67.             gxVw.Camera.Zoom factor
  68.             Exit Sub
  69.             
  70.         Else
  71.             gxVw.ZoomToExtents
  72.         End If
  73.     End If
  74.     Exit Sub
  75. VwZoom:
  76.         Dim xC As Double
  77.         Dim yC As Double
  78.         
  79.         Dim w As Double
  80.         Dim h As Double
  81.     
  82.         On Error GoTo Err
  83.         w = gxVw.ViewWidth
  84.         h = gxVw.ViewHeight
  85.     
  86.         xC = gxVw.ViewLeft + w / 2
  87.         yC = gxVw.ViewTop - h / 2
  88.     
  89.         w = w * factor
  90.         h = h * factor
  91.     
  92.         gxVw.Update = False
  93.         
  94.         gxVw.ViewLeft = xC - w / 2
  95.         gxVw.ViewTop = yC + h / 2
  96.     
  97.         gxVw.ViewWidth = w
  98.         gxVw.ViewHeight = h
  99. Err:
  100. End Sub
  101.  
  102. Public Function Detach() As Boolean
  103.     
  104.     On Error Resume Next
  105.     If (Not gxVw Is Nothing) Then
  106.         gxVw.Delete
  107.         Set gxVw = Nothing
  108.     End If
  109.     
  110.     If (Not gxDwg Is Nothing) Then
  111.         Set gxDwg = Nothing
  112.     End If
  113.     bAttached = False
  114.     
  115.     Detach = bAttached
  116.     
  117. End Function
  118. Public Function Attach(objDwg As Object) As Boolean
  119.  
  120.     Dim gxProps As Properties
  121.     Dim gxProp As Property
  122.     
  123.     On Error GoTo Err
  124.     
  125.     Detach
  126.     
  127.     Set gxDwg = objDwg
  128.     Set gxProps = gxDwg.Application.Properties
  129.     Set gxProp = gxProps("Aperture")
  130.     
  131.     dblAperture = gxProp
  132.     
  133.     Set gxProp = Nothing
  134.     Set gxProps = Nothing
  135.     
  136.     Set gxVw = gxDwg.Views.Add(hWnd)
  137.     gxVw.ZoomToExtents
  138.     
  139.     bAttached = True
  140.  
  141. Err:
  142.     If (Err <> 0) Then
  143.         MsgBox Err.Description
  144.     End If
  145.     
  146.     Attach = bAttached
  147. End Function
  148.  
  149. Private Sub UserControl_Initialize()
  150.     bAttached = False
  151.     bUpdate = True
  152.     Set gxVw = Nothing
  153.     Set gxDwg = Nothing
  154.     dblAperture = 1
  155. End Sub
  156.  
  157. Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  158.  
  159.     Dim xVw As Double
  160.     Dim yVw As Double
  161.     Dim xW As Double
  162.     Dim yW As Double
  163.     Dim zW As Double
  164.     
  165.     Dim gxPickRes As PickResult
  166.     Dim gxPickEntry As PickEntry
  167.     Dim cnt As Long
  168.     Dim ind As Long
  169.     
  170.     If (bAttached) Then
  171.     
  172.         gxVw.ScreenToView X, Y, xVw, yVw
  173.         
  174.         Set gxPickRes = gxVw.PickPoint(xVw, yVw, dblAperture, True, True, True, True, True, False)
  175.     
  176.         cnt = gxPickRes.Count - 1
  177.         For ind = 0 To cnt
  178.             Set gxPickEntry = gxPickRes.Item(ind)
  179.             RaiseEvent ClickGraphic(gxPickEntry.Graphic, gxPickEntry.Distance)
  180.         Next ind
  181.     
  182.     End If
  183.  
  184.     Set gxPickEntry = Nothing
  185.     Set gxPickRes = Nothing
  186.  
  187.     Refresh
  188. End Sub
  189.  
  190. Private Sub UserControl_Paint()
  191.     If (bAttached And bUpdate) Then
  192.         On Error Resume Next
  193.         gxVw.Refresh
  194.     End If
  195. End Sub
  196.  
  197. Private Sub UserControl_Terminate()
  198.     
  199.     Detach
  200.  
  201. End Sub
  202.  
  203. Public Property Get ViewSpace() As Variant
  204.     If (Not gxVw Is Nothing) Then
  205.         ViewSpace = gxVw.SpaceMode
  206.     End If
  207. End Property
  208.  
  209. Public Property Let ViewSpace(ByVal vNewValue As Variant)
  210.     Dim bSpace As ImsiSpaceModeType
  211.     bSpace = vNewValue
  212.     If (Not gxVw Is Nothing) Then
  213.         gxVw.SpaceMode = bSpace
  214.         gxVw.Refresh
  215.     End If
  216. End Property
  217.  
  218. Public Property Get Aperture() As Variant
  219.     Aperture = dblAperture
  220. End Property
  221.  
  222. Public Property Let Aperture(ByVal vNewValue As Variant)
  223.     dblAperture = vNewValue
  224. End Property
  225.  
  226. Public Property Get Update() As Variant
  227.     Update = bUpdate
  228. End Property
  229.  
  230. Public Property Let Update(ByVal vNewValue As Variant)
  231.     bUpdate = vNewValue
  232. End Property
  233.